﻿Public Class NeuerArtikelFRM

#Region " D e k l a r a t i o n e n "
    Private EAN As String
    Private MengenIdLIS As New List(Of Integer)
    Public EanID As Integer
#End Region

#Region " K o n s t r u k t o r "
    Public Sub New(EanScan As String)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        EAN = EanScan
    End Sub
#End Region

#Region " NeuerArtikelFRM_Load-Ereignis "
    Private Sub NeuerArtikelFRM_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim tmpSQL As String = "SELECT " & TBL.Mengeneinheiten.Name &
            ", " & TBL.Mengeneinheiten.Id &
            " FROM " & TBL.Mengeneinheiten.TBL &
            " ORDER BY " & TBL.Mengeneinheiten.Name & " ASC"
        For Each row As DataRow In DB.BildeDataSet(tmpSQL).Tables(0).Rows
            Me.ComboBoxME1.Items.Add(row(0).ToString)
            Me.ComboBoxME2.Items.Add(row(0).ToString)
            MengenIdLIS.Add(CInt(row(1)))
        Next
    End Sub
#End Region

#Region " ButtonOk_Click-Ereignis "
    Private Sub ButtonOk_Click(sender As Object, e As EventArgs) Handles ButtonOk.Click
        If Me.TextBoxName.Text <> "" AndAlso Me.ComboBoxME1.Text <> "" AndAlso Me.ComboBoxME2.Text <> "" Then
            Dim neueID As Integer = DB.HoleNächstenFreieID(TBL.Artikel.TBL)
            Dim tmpSQL As String = "INSERT INTO Artikel (id, Name, LagerBestandME1, LagerBestandME2, ME1, ME2) VALUES (" & neueID & ", '" & Me.TextBoxName.Text & "', 0, 0, " & MengenIdLIS(Me.ComboBoxME1.SelectedIndex) & ", " & MengenIdLIS(Me.ComboBoxME2.SelectedIndex) & ")"
            DB.InsertDeleteUpdate(tmpSQL)
            EanID = DB.HoleNächstenFreieID(TBL.EANcodes.TBL)
            tmpSQL = "INSERT INTO " & TBL.EANcodes.TBL & "(" & TBL.EANcodes.Id & ", " & TBL.EANcodes.Code & ", " & TBL.EANcodes.Artikel & ", " & TBL.EANcodes.MeUmrechnungsfaktor & ") VALUES (" &
              EanID & ", '" & EAN & "', " & neueID & ", '" & CDbl(Me.TextBoxUmrechnungsFaktor.Text).ToString & "')"
            DB.InsertDeleteUpdate(tmpSQL)
            Me.DialogResult = DialogResult.OK
        End If
    End Sub
#End Region

#Region " ComboBoxME1_SelectedIndexChanged-Ereignis "
    Private Sub ComboBoxME1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBoxME1.SelectedIndexChanged
        If Me.ComboBoxME1.Text <> "" Then
            Me.LabelUmrechnung1.Text = "1 " & Me.ComboBoxME1.Text & " entspricht"
        Else
            Me.LabelUmrechnung1.Text = "1 <ME1> entspricht"
        End If
    End Sub
#End Region

#Region " ComboBoxME2_SelectedIndexChanged-Ereignis "
    Private Sub ComboBoxME2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBoxME2.SelectedIndexChanged
        If Me.ComboBoxME2.Text <> "" Then
            Me.LabelUmrechnung2.Text = Me.ComboBoxME2.Text
        Else
            Me.LabelUmrechnung2.Text = "<ME2>"
        End If
    End Sub
#End Region

End Class